

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBconn
{
	private static Connection dbconn;
	public static Connection getConnection() throws SQLException,ClassNotFoundException
	{
		if (dbconn==null) 
		{
			String url = "jdbc:oracle:thin:@192.168.0.21:1521:XE";
			String user="hr";
			String password="hr";
			
			Class.forName("oracle.jdbc.driver.OracleDriver");
			System.out.println("Driver Loading");
			
			//2. 오라클 DB와 연결
			dbconn = DriverManager.getConnection(url, user, password);
			System.out.println("DataBase Connected");
		}
		return dbconn;
	}
	
	public static void close() throws SQLException
	{
		if (dbconn!=null) 
		{
			if (!dbconn.isClosed()) 
			{
				dbconn.close();
			}
		}
		dbconn=null;
	}
	
	public static void main(String[] args) throws ClassNotFoundException, SQLException 
	{
		DBconn con = new DBconn();
		Connection conn = con.getConnection();
	}
}
